package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.PartnerVehicleTradeApproveVO;
import com.yunxi.sto.pojo.PartnerVehicleTradeVO;
import com.yunxi.sto.service.PartnerVehicleTradeDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 渠道商车辆买卖 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-08-30
 */
@RestController
@RequestMapping("/admin/partnerVehicleTrade")
@Api(tags = "sto:partnerVehicleTrade", description = "渠道商车辆买卖接口")
public class PartnerVehicleTradeController {
    private static final Logger logger = LoggerFactory.getLogger(PartnerVehicleTradeController.class);

    @Autowired
    PartnerVehicleTradeDubboService partnerVehicleTradeDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询渠道商车辆买卖分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeVO.setOutPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(partnerVehicleTradeDubboService.findPageByVO(partnerVehicleTradeVO, pageNum, pageSize));
    }

    @GetMapping("/detailList")
    @ApiOperation(value = "买卖车辆详情列表")
    @ApiImplicitParam(paramType="query", name = "tradeId", value = "主键ID", required = true, dataType = "String")
    public ApiResult detailList(String tradeId) throws Exception {
        return ResponseUtil.ok(partnerVehicleTradeDubboService.detailList(tradeId));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个渠道商车辆买卖")
    @ApiImplicitParam(paramType="query", name = "tradeId", value = "主键ID", required = true, dataType = "String")
    public ApiResult load(String tradeId) throws Exception {
        return ResponseUtil.ok(partnerVehicleTradeDubboService.getById(tradeId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存渠道商车辆买卖信息")
    public ApiResult save(@RequestBody PartnerVehicleTradeVO partnerVehicleTradeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeDubboService.saveOrUpdate(partnerVehicleTradeVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/saleFromManager")
    @ApiOperation(value = "卖方小区经理审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult saleFromManager(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
//        partnerVehicleTradeVO.setOutPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(partnerVehicleTradeDubboService.saleFromManager(partnerVehicleTradeVO, pageNum, pageSize,1));
    }

    @PostMapping("/saleFromMpass")
    @ApiOperation(value = "卖方小区经理审核通过")
    public ApiResult saleFromMpass(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(2);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/saleFromMreturn")
    @ApiOperation(value = "卖方小区经理审核驳回")
    public ApiResult saleFromMreturn(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(3);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/saleFromAreaM")
    @ApiOperation(value = "卖方大区经理审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult saleFromAreaM(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
//        partnerVehicleTradeVO.setOutPartnerCode(loginInfo.getPartnerCode());
        partnerVehicleTradeVO.setUserCode(loginInfo.getUserCode());
        return ResponseUtil.ok(partnerVehicleTradeDubboService.saleFromManager(partnerVehicleTradeVO, pageNum, pageSize,2));
    }

    @PostMapping("/saleFromApass")
    @ApiOperation(value = "卖方大区经理审核通过")
    public ApiResult saleFromApass(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(4);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/saleFromAreturn")
    @ApiOperation(value = "卖方大区经理审核驳回")
    public ApiResult saleFromAreturn(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(5);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/saleToAreaM")
    @ApiOperation(value = "买方大区经理审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult saleToAreaM(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
//        partnerVehicleTradeVO.setOutPartnerCode(loginInfo.getPartnerCode());
        partnerVehicleTradeVO.setUserCode(loginInfo.getUserCode());
        return ResponseUtil.ok(partnerVehicleTradeDubboService.saleFromManager(partnerVehicleTradeVO, pageNum, pageSize,3));
    }

    @PostMapping("/saleToApass")
    @ApiOperation(value = "买方大区经理审核通过")
    public ApiResult saleToApass(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(6);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/saleToAreturn")
    @ApiOperation(value = "买方大区经理审核驳回")
    public ApiResult saleToAreturn(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(7);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/factoryApprove")
    @ApiOperation(value = "总部审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult factoryApprove(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(partnerVehicleTradeDubboService.saleFromManager(partnerVehicleTradeVO, pageNum, pageSize,4));
    }

    @PostMapping("/factoryPass")
    @ApiOperation(value = "总部审核通过")
    public ApiResult factoryPass(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(8);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/factoryReturn")
    @ApiOperation(value = "总部审核驳回")
    public ApiResult factoryReturn(@RequestBody PartnerVehicleTradeApproveVO partnerVehicleTradeApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerVehicleTradeApproveVO.setApproveStatus(9);
        partnerVehicleTradeDubboService.approve(partnerVehicleTradeApproveVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/approveHis")
    @ApiOperation(value = "审核历史分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult approveHis(PartnerVehicleTradeVO partnerVehicleTradeVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(partnerVehicleTradeDubboService.approveHis(partnerVehicleTradeVO, pageNum, pageSize));
    }

//    @PostMapping("/del")
//    @ApiOperation(value = "删除渠道商车辆买卖")
//    public ApiResult del(@RequestBody List<PartnerVehicleTradeVO> partnerVehicleTradeVOList) throws Exception {
//        partnerVehicleTradeDubboService.removeByListVo(partnerVehicleTradeVOList);
//        return ResponseUtil.ok("success");
//    }

    //    @GetMapping("/list")
//    @ApiOperation(value = "查询渠道商车辆买卖列表")
//    public ApiResult list(PartnerVehicleTradeVO partnerVehicleTradeVO) throws Exception {
//        return ResponseUtil.ok(partnerVehicleTradeDubboService.listByVo(partnerVehicleTradeVO));
//    }

}
